package stores

import (
	"jvm/instructions/base"
	"jvm/rtda"
)

// ISTORE Store int into local variable
type ISTORE struct{ base.Index8Instruction }

func (is *ISTORE) Execute(jFrame *rtda.JFrame) {
	_istore(jFrame, is.Index)
}

type ISTORE_0 struct{ base.NoOperandsInstruction }

func (is *ISTORE_0) Execute(jFrame *rtda.JFrame) {
	_istore(jFrame, 0)
}

type ISTORE_1 struct{ base.NoOperandsInstruction }

func (is *ISTORE_1) Execute(jFrame *rtda.JFrame) {
	_istore(jFrame, 1)
}

type ISTORE_2 struct{ base.NoOperandsInstruction }

func (is *ISTORE_2) Execute(jFrame *rtda.JFrame) {
	_istore(jFrame, 2)
}

type ISTORE_3 struct{ base.NoOperandsInstruction }

func (is *ISTORE_3) Execute(jFrame *rtda.JFrame) {
	_istore(jFrame, 3)
}

func _istore(jFrame *rtda.JFrame, index uint) {
	val := jFrame.OperandStack().PopInt()
	jFrame.LocalVars().SetInt(index, val)
}
